﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Prodma.DataAccess.Models.UserControlViewModels.NavigationVm>" %>

<% string url = "?"; %>
<% if (ViewData.Model.Keys != null) %>
<% { %>
     <% for (int i = 0; i < ViewData.Model.Keys.Count; i++) %>
     <% { %>
          <% url += ViewData.Model.Keys[i] + "=" + ViewData.Model.Values[i] + "&"; %>
     <% } %>
<% } %>


<ul class="navigation">
      <li>
        <a href='/home/index/'>
            <img src="../../Images/ListImages/exit.png" alt="" />
            <p>Çıkış</p>
        </a>
      </li>
  <% if (ViewData.Model.Update == true) %>
  <% { %>
        <li>
            <a href="#" onclick="setPassiveRecord();">
                <img src="../../Images/ListImages/passive.png" alt="" />
                <p>Pasif</p>
            </a>
        </li>
        <li>
            <a href="#" onclick="setActiveRecord();">
                <img src="../../Images/ListImages/active.png" alt="" />
                <p>Aktif</p>
            </a>
        </li>
  <% } %>
  <% if (ViewData.Model.Delete == true) %>
  <% { %>
        <li>
            <a href="#" onclick="deleteRow();">
                <img src="../../Images/ListImages/delete.png" alt="" />
                <p>Sil</p>
            </a>
        </li>
  <% } %>
  <% if (ViewData.Model.Update == true) %>
  <% { %>
        <li>
            <a href="#" onclick="editRow();">
                <img src="../../Images/ListImages/edit.png" alt="" />
                <p>Düzenle</p>
            </a>
        </li>
  <% } %>
  <% if (ViewData.Model.Write == true) %>
  <% { %>
        <li>
            <a href='/<%=ViewData.Model.View %>/new/<%=url %>'>
                <img src="../../Images/ListImages/new.png" alt="" />
                <p>Yeni</p>
            </a>
        </li>
  <% } %>
        <li>
            <a href="#" onclick="editRow();">
                <img src="../../Images/ListImages/shoppingcart.png" alt="" />
                <p>Sepete Ekle</p>
            </a>
        </li>
  
</ul>

<input type="hidden" id="viewName" value='<%=ViewData.Model.View %>' />

<script type="text/javascript">
    function deleteRow() {
        var result = confirm('Seçili kayıt(lar) silinsin mi?');
        if (!result)
            return false;

        var idList = new Array();

        $("input[@name=chkSelect][checked]").each(
              function() {
                  if (this.id != 'chk') {
                      idList.push(this.id);
                  }
              }
            );

        if (idList.length == 0)
            return false;

        var viewName = document.getElementById('viewName').value;
        window.location.replace('/' + viewName +'/delete/?idList=' + idList);
    }
    function editRow() {
        var viewName = document.getElementById('viewName').value;
        $("input[@name=chkSelect][checked]").each(
              function() {
                  if (this.id != 'chk') {

                      window.location.replace('/' + viewName + '/edit/?id=' + this.id.substring(3, this.id.length));
                  }
              }
            );
          }

          function setActiveRecord() {
              var result = confirm('Seçili kayıt(lar) aktif hale getirilsin mi?');
              if (!result)
                  return false;

              var idList = new Array();

              $("input[@name=chkSelect][checked]").each(
              function() {
                  if (this.id != 'chk') {
                      idList.push(this.id);
                  }
              }
            );

              if (idList.length == 0)
                  return false;

              var viewName = document.getElementById('viewName').value;
              window.location.replace('/' + viewName + '/setActive/?idList=' + idList);
          }
          function setPassiveRecord() {
              var result = confirm('Seçili kayıt(lar) pasif hale getirilsin mi?');
              if (!result)
                  return false;

              var idList = new Array();

              $("input[@name=chkSelect][checked]").each(
              function() {
                  if (this.id != 'chk') {
                      idList.push(this.id);
                  }
              }
            );

              if (idList.length == 0)
                  return false;

              var viewName = document.getElementById('viewName').value;
              window.location.replace('/' + viewName + '/setPassive/?idList=' + idList);
          }
    
    
</script>